package com.push.notifications;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.push.cache.ImageLoader;
import android.view.ViewGroup.LayoutParams;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class popupWebview extends Activity{
	
	public static String titleDialog;
	public static String descriptonDialg;
	public static String urlImage;
	public static String sortContentDialog;
	public static String sCommand;
	public static String sUrl;
	public static boolean bLink;
	public static boolean bAdmin;
	public ImageLoader imageLoaderDialog;
	public static WebViewBasic webInMessageDialog;
	public static Handler han_popupWebview;
	public static boolean islive;
	private boolean bFinal= false;
	public static boolean starFromPopup = false;
	

	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		 setContentView(R.layout.message);
		 GCMIntentService.web_islive= true;
		ImageButton buttonClose1 = (ImageButton) findViewById(R.id.imageButton12);
		buttonClose1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	//close Activitys
                finish();
            }
        });
		han_popupWebview = new Handler() {

            public void handleMessage(Message msg) {
                super.handleMessage(msg);

                switch(msg.what) {

                case 0:
                	finish();
                    break;

                }
            }

        };
		
		TextView TextZinZin = (TextView) findViewById(R.id.TittleReceive);
		TextZinZin.setText(titleDialog);
		
		webInMessageDialog = (WebViewBasic) findViewById(R.id.popup_webView);
		
		ImageView ImageMessage = (ImageView) findViewById(R.id.imageView1);
		
		Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        if (width >height) {width = height;}
        
        RelativeLayout dialogeSX = (RelativeLayout) findViewById(R.id.mesage203);
        LayoutParams frame = dialogeSX.getLayoutParams();
        frame.width = width*90/100;
        frame.height = width*90/100;
        dialogeSX.setLayoutParams(frame);
		
		WebSettings webSettings = webInMessageDialog.getSettings();

		webSettings.setJavaScriptEnabled(true);

		if(sUrl != null && sUrl.equalsIgnoreCase(""))
		{
			webInMessageDialog.loadData("Webview is empty ", "text/html", "UTF-8");
		}
		else
		{
			 //String WebContent = sortContentDialog;
			 //webInMessageDialog.loadData( WebContent, "text/html", "UTF-8");
			webInMessageDialog.loadUrl(sUrl);
		}
		//
	
	}
	

	  @Override
	public void onWindowFocusChanged(boolean hasFocus) {
	  if (hasFocus)
	  {
		  GCMIntentService.AppInterrupt =false;
	  }
	// TODO Auto-generated method stub
	  Log.e("popupWebview", ": ------onWindowFocusChanged------------ onWindowFocusChanged-"+ GCMIntentService.AppInterrupt);
	super.onWindowFocusChanged(hasFocus);
	}
	@Override
	protected void 	onUserLeaveHint(){
		//GCMIntentService.AppInterrupt =true;
		Log.e("popupWebview", "onUserLeaveHint: ------onUserLeaveHint------------ "+ GCMIntentService.AppInterrupt);
		super.onUserLeaveHint();
	}
	@Override
	public void finish() {
		GCMIntentService.web_islive= false;
		Log.e("popupWebview", "finish: ------finish------------ "+ GCMIntentService.AppInterrupt);
		// TODO Auto-generated method stub
		super.finish();
	}

	
	
}
